package com.itboye.mengwu.app.ui.mymeng;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Observable;
import java.util.Observer;

import android.app.Dialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.drawable.Drawable;
import android.text.Editable;
import android.text.Html;
import android.text.Html.ImageGetter;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.itboye.config.GlobalConfig;
import com.itboye.core.alert.ByAlert;
import com.itboye.core.object.BaseActivity;
import com.itboye.core.object.ResultEntity;
import com.itboye.core.object.SpPublicParams;
import com.itboye.core.utils.SPUtils;
import com.itboye.core.utils.XImageLoader;
import com.itboye.inageview.RoundImageView;
import com.itboye.mengwu.R;
import com.itboye.mengwu.app.ui.aiwujia.YuErJingMomDetailActivity;
import com.itboye.mengwu.app.ui.main.ActivityReport;
import com.itboye.mengwu.chatemoji.FaceInputView;
import com.itboye.mengwu.chatemoji.FaceInputView.Face;
import com.itboye.mengwu.chatemoji.FaceInputView.OnFaceClickListener;
import com.itboye.mengwu.data.model.BaoBaoLePingLunAndHuiFuModel;
import com.itboye.mengwu.data.model.BaoBaoLePingLunAndHuiFuModel.ReplyContent;
import com.itboye.mengwu.data.model.LuntanTieZiBean;
import com.itboye.mengwu.data.model.TieZiBaoHanReply.GetAList;
import com.itboye.mengwu.data.model.TieZiBaoHanReply.GetAList.ReplyInfo.ReContent;
import com.itboye.mengwu.data.presenter.TieZiPresenter;
import com.itboye.mengwu.luntan.comment.view.MyListView;
import com.itboye.sunsun.volley.Spanned2String;

public class WoDeDongTaiDetail2 extends BaseActivity implements Observer {

	TieZiPresenter presenter;
	private String tid, toUid;
	RoundImageView author_headewrshow;
	ImageView img_collection, back;
	LinearLayout biaoqian_lin, image_container;
	TextView author_name, baby_years, guanzhu, question_show, pinglun_num,
			shoucang_num, txt_send;
	MyListView list_wodedongtaidetail;
	EditText edit_content;
	private GetAList bean;
	final int ONE_COMMENT_CODE = -1;
	String type = "评论";
	protected String pid;
	protected String authorId;
	ImageView img_pinglun;
	boolean isShowKeyBord = false, isGuanZhu = false;
	LinearLayout faceInputContainer;
	ImageView emoji;
	// ArrayList<String> arrayList = new ArrayList<String>();
	protected FaceInputView faceInputView;
	boolean isShowEmotion = false;
	RelativeLayout mom_answer_linear;
	String sex, birth;
	TextView baby_sex;
	TextView txt_title;
	ImageView img_other;

	// ImageView img_other;

	@Override
	public int initView() {
		// TODO Auto-generated method stub
		return R.layout.activity_wodedongtail_2;
	}

	@Override
	public void onMyCreate() {
		// arrayList = getIntent().getStringArrayListExtra("img");
		uid = "" + SPUtils.get(this, null, SpPublicParams.UID, "");
		faceInputView = new FaceInputView(getApplicationContext());
		img_other.setVisibility(View.VISIBLE);
		img_other.setImageResource(R.drawable.report);
		faceInputContainer.addView(faceInputView);
		txt_title.setText("宝宝乐详情");

		faceInputView.setOnClickListener(new FaceInputListenr());

		final LuntanTieZiBean model = new LuntanTieZiBean();
		model.setUid(SPUtils.get(WoDeDongTaiDetail2.this, null,
				SpPublicParams.UID, "") + "");

		showProgressDialog("数据加载中，请稍后", true);
		getYuanTie();
		back.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});
		img_other.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (uid == toUid || uid.equals(toUid)) {
					ByAlert.alert("不能举报自己哦");
					return;
				} else {
					Intent intent = new Intent(WoDeDongTaiDetail2.this,
							ActivityReport.class);
					intent.putExtra("Report_type", "0");
					intent.putExtra("Op_uid", uid);
					intent.putExtra("toUid", toUid);
					intent.putExtra("Report_id", tid);
					startActivity(intent);
				}

			}
		});

		edit_content.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE))
						.showSoftInput(edit_content, 0);
				faceInputContainer.setVisibility(View.GONE);
				isShowEmotion = false;
			}
		});
		emoji.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (!isShowEmotion) {
					faceInputContainer.setVisibility(View.VISIBLE);
				} else {
					faceInputContainer.setVisibility(View.GONE);
				}
				isShowEmotion = !isShowEmotion;
				((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE))
						.hideSoftInputFromWindow(WoDeDongTaiDetail2.this
								.getCurrentFocus().getWindowToken(),
								InputMethodManager.HIDE_NOT_ALWAYS);
			}
		});

		txt_send.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (type.equals("评论")) {
					if (edit_content.getText() == null) {
						ByAlert.alert("请先输入内容");
						return;
					}
					showProgressDialog("提交中，请稍后", true);
					presenter.pinglun(bean.getFid(), bean.getTid(),
							(String) SPUtils.get(WoDeDongTaiDetail2.this, null,
									SpPublicParams.UID, ""), Spanned2String
									.parse(edit_content.getText()), null, "");
				} else {

					showProgressDialog("提交中，请稍后", true);
					presenter.huiFuPingLun("4", pid, tid, uid,
							Spanned2String.parse(edit_content.getText()),
							authorId);
				}
				KeyBoard(edit_content, "我也说一句");
			}
		});
		img_collection.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				showProgressDialog("提交中，请稍后", true);
				if (v.getTag().toString().equals("0")) {
					Log.e("hu  uid", tid);
					presenter.dianzan(tid, uid, "1");
					v.setTag("1");
				} else {
					presenter.dianzan(tid, uid, "0");
					v.setTag("0");
				}
			}
		});
		list_wodedongtaidetail
				.setOnItemClickListener(new OnItemClickListener() {

					@Override
					public void onItemClick(AdapterView<?> parent, View view,
							final int position, long id) {
						authorId = andHuiFuModel.getList().get(position)
								.getAuthorId();
						if (authorId.equals(uid)) {
							final Dialog customDialog = new Dialog(
									WoDeDongTaiDetail2.this, R.style.dialog);
							LayoutInflater inflater = WoDeDongTaiDetail2.this
									.getLayoutInflater();
							View mView = inflater
									.inflate(
											R.layout.dialog_delete_replyorcomment,
											null);
							TextView delete = (TextView) mView
									.findViewById(R.id.delete);
							TextView cancel = (TextView) mView
									.findViewById(R.id.cancel);
							// LayoutParams params=new
							// LayoutParams(getActivity().getWindowManager().getDefaultDisplay().getWidth(),100);
							// mView.setLayoutParams(params);
							customDialog
									.requestWindowFeature(Window.FEATURE_NO_TITLE);
							customDialog.setContentView(mView);

							customDialog.show();
							delete.setOnClickListener(new OnClickListener() {

								@Override
								public void onClick(View v) {
									showProgressDialog("删除中，请稍后", true);
									if (andHuiFuModel.getList().get(position)
											.getId().equals("0")) {// 评论的删除
										presenter
												.deletePingLun(authorId, "4",
														andHuiFuModel.getList()
																.get(position)
																.getTid(),
														andHuiFuModel.getList()
																.get(position)
																.getPid());
									} else {// 评论的回复的删除
										presenter
												.deleteComment(uid,
														andHuiFuModel.getList()
																.get(position)
																.getTid(),
														andHuiFuModel.getList()
																.get(position)
																.getPid(),
														andHuiFuModel.getList()
																.get(position)
																.getId());
									}
								}
							});
							cancel.setOnClickListener(new OnClickListener() {

								@Override
								public void onClick(View v) {
									// TODO Auto-generated method stub
									customDialog.dismiss();
								}
							});

						} else {
							pid = bean.getReplyInfo().getList().get(position)
									.getPid();
							authorId = bean.getReplyInfo().getList()
									.get(position).getAuthorId();
							KeyBoard(
									edit_content,
									"回复"
											+ bean.getReplyInfo().getList()
													.get(position).getAuthor());
							type = "回复评论";
						}
					}
				});
		img_pinglun.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				type = "评论";
				KeyBoard(edit_content, "评论");
			}
		});

		guanzhu.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				showProgressDialog("数据加载中，请稍后", true);

				if (guanzhu.getText().toString().equals("删除")) {
					model.setTid(tid);
					presenter.delete(model);
					finish();
				} else {
					if (isGuanZhu) {
						presenter.guanzhu(uid, toUid, "0");// 取消关注
					} else {
						presenter.guanzhu(uid, toUid, "1");// 关注
					}
				}

			}
		});

	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			if (faceInputContainer.getVisibility() == View.VISIBLE) {
				faceInputContainer.setVisibility(View.GONE);
				isShowEmotion = false;
				return false;
			} else {
				finish();
			}
		}
		return super.onKeyDown(keyCode, event);
	}

	private class FaceInputListenr implements OnFaceClickListener {

		@Override
		public void selectedFace(Face face) {
			int id = face.faceId;
			if (id == R.drawable.ic_face_delete_normal)// 删除按钮
			{
				int index = edit_content.getSelectionStart();
				if (index == 0)
					return;
				Editable editable = edit_content.getText();
				editable.delete(index - 1, index);// 删除最后一个字符或表情
			} else {
				edit_content.append(Html.fromHtml("<img src='" + id + "'/>",
						imageGetter, null));// 添加表情
			}
		}

	}

	// 输入表情需要
	ImageGetter imageGetter = new ImageGetter() {
		@Override
		public Drawable getDrawable(String source) {
			int id = Integer.parseInt(source);
			Drawable d = getResources().getDrawable(id);
			d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
			return d;
		}
	};
	private BaoBaoLePingLunAndHuiFuModel andHuiFuModel;

	public void getYuanTie() {
		presenter = new TieZiPresenter(this);
		tid = getIntent().getStringExtra("tid");
		presenter = new TieZiPresenter(this);
		presenter.zhutiXiangqing(
				SPUtils.get(this, null, SpPublicParams.UID, "") + "", tid, "3");
	}

	// 输入法是否显示着
	public void KeyBoard(EditText edittext, String author) {
		// 1、//隐藏软键盘
		// ((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(WoDeDongTaiDetail2.this.getCurrentFocus().getWindowToken(),
		// InputMethodManager.HIDE_NOT_ALWAYS);
		// 2、//显示软键盘,控件ID可以是EditText,TextView
		if (isShowKeyBord == false) {
			((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE))
					.showSoftInput(edittext, 0);
			edittext.setHint(author);
		} else {
			((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE))
					.hideSoftInputFromWindow(WoDeDongTaiDetail2.this
							.getCurrentFocus().getWindowToken(),
							InputMethodManager.HIDE_NOT_ALWAYS);
		}
		edittext.setText("");
		isShowKeyBord = !isShowKeyBord;

	}

	void Baby(String babysex, String babyBirth) {
		if (babysex != null) {
			if ("0".equals(babysex)) {
				sex = ("女宝");
			} else if ("1".equals(babysex)) {
				sex = ("男宝");

			} else {
				sex = ("孕育中");
			}
			SimpleDateFormat myFmt1 = new SimpleDateFormat("yyyy年MM月dd日");
			Calendar calendar = Calendar.getInstance();
			int yearNow = calendar.get(Calendar.YEAR);
			int monthNow = calendar.get(Calendar.MONTH);
			int dayNow = calendar.get(Calendar.DAY_OF_MONTH);
			Calendar calendar2 = Calendar.getInstance();
			if (babysex != null && babyBirth != null) {
				long timews = Long.valueOf(babyBirth);
				Date date = new Date(timews * 1000L);
				calendar2.setTime(date);
				int yearBirth = calendar2.get(Calendar.YEAR);
				int monthBirth = calendar2.get(Calendar.MONTH);
				int dayBirth = calendar2.get(Calendar.DAY_OF_MONTH);
				int age = yearNow - yearBirth;
				int month = monthNow - monthBirth;
				int day = dayNow - dayBirth;
				if (day < 0) {
					month -= 1;
					calendar2.add(Calendar.MONTH, -1);// 得到上一个月，用来得到上个月的天数。
					day = day
							+ calendar2.getActualMaximum(Calendar.DAY_OF_MONTH);
				}
				if (month < 0) {
					month = (month + 12) % 12;
					age--;
				}
				int days = day + 1;
				int months = month + 1;
				if (age == 0) {
					if (month == 0) {
						birth = (days + "天");
					} else {
						birth = (months + "月" + days + "天");
					}
				} else {
					if (month == 0) {
						birth = (age + "岁" + days + "天");
					} else {
						birth = (age + "岁" + months + "月" + days + "天");
					}
				}
			}
		}
	}

	@SuppressWarnings("deprecation")
	@Override
	public void update(Observable observable, Object data) {
		// TODO Auto-generated method stub
		ResultEntity entity = handlerError(data);
		if (entity != null) {
			if (uid == toUid) {
				img_other.setVisibility(View.GONE);
			} else {
				img_other.setVisibility(View.VISIBLE);
			}
			if (entity.getEventType() == TieZiPresenter.XiangQingSuccess) {
				bean = (GetAList) entity.getData();
				author_name.setText(bean.getAuthor());
				question_show.setText(bean.getMessage());
				toUid = bean.getAuthorId();
				if (bean.getIsFocus().equals("0")) {
					isGuanZhu = false;
					guanzhu.setText("+关注");
					guanzhu.setTextColor(getResources().getColor(
							R.color.main_color));
				} else {
					isGuanZhu = true;
					guanzhu.setText("已关注");
					guanzhu.setTextColor(getResources().getColor(R.color.black));
				}
				if (bean.getAuthorId().equals(uid)) {
					guanzhu.setText("删除");
					guanzhu.setTextColor(getResources().getColor(
							R.color.main_color));
				}
				// XImageLoader.load(GlobalConfig.API_URL + "/picture/index?id="
				// + bean.getHead(), author_headewrshow);
				if ("".equals(bean.getHead()) || bean.getHead() == null) {
					if ("1".equals(bean.getSex())) {
						author_headewrshow.setImageResource(R.drawable.male);
					} else {
						author_headewrshow.setImageResource(R.drawable.female);
					}

				} else {
					if (!bean.getHead().startsWith("http")) {
						XImageLoader.load(GlobalConfig.API_URL
								+ "/picture/index?id=" + bean.getHead(),
								author_headewrshow);
					} else {
						XImageLoader.load(bean.getHead(), author_headewrshow);
					}

				}
				if (bean.getIsLike().equals("1")) {
					img_collection.setBackgroundResource(R.drawable.xin_pink);
					img_collection.setTag("1");
				} else {
					img_collection
							.setBackgroundResource(R.drawable.like_unselect);
					img_collection.setTag("0");
				}
				if (bean.getBabyDefault() != null) {
					if (bean.getBabyDefault().getSex() != null
							&& bean.getBabyDefault().getBirthday() != null) {
						baby_sex.setVisibility(View.VISIBLE);
						baby_years.setVisibility(View.VISIBLE);
						Baby(bean.getBabyDefault().getSex(), bean
								.getBabyDefault().getBirthday());
						baby_years.setText(birth);
						baby_sex.setText(sex);
					}

				} else {
					baby_sex.setVisibility(View.GONE);
					baby_years.setVisibility(View.GONE);
				}
				shoucang_num.setText(bean.getLikes());
				pinglun_num.setText(bean.getReplies());
				image_container.removeAllViews();
				if (bean.getImg() != null) {
					if (bean.getImg().size() > 0) {
						for (int j = 0; j < bean.getImg().size(); j++) {

							ImageView imageView = new ImageView(this);
							LayoutParams layoutParams = new LayoutParams(
									(int) getResources().getDimension(
											R.dimen.tizie_imageview_width),
									(int) getResources().getDimension(
											R.dimen.tizie_imageview_width));
							layoutParams.setMargins(5, 5, 5, 5);
							imageView.setLayoutParams(layoutParams);
							imageView.setLayoutParams(layoutParams);
							XImageLoader.load(
									GlobalConfig.API_URL + "/picture/index?id="
											+ bean.getImg().get(j), imageView);
							image_container.addView(imageView);
						}
					}
				}
				// tid
				presenter.baoBaoLeDetailComment(uid, tid);
				//
			} else if (entity.getEventType() == TieZiPresenter.XiangQingFail) {
				ByAlert.alert("数据查询失败");
			} else if (entity.getEventType().equals(
					"com.itboye.core.object.BaseActivity_unknown")) {
				// ByAlert.alert(entity.getData() + "1");
				edit_content.setText("");
				View view = getWindow().peekDecorView();
				InputMethodManager inputmanger = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
				inputmanger.hideSoftInputFromWindow(view.getWindowToken(), 0);
				getYuanTie();
			} else if (entity.getEventType() == TieZiPresenter.PingLunFail) {
				// ByAlert.alert(entity.getData() + "");
			} else if (entity.getEventType() == TieZiPresenter.huiFuPinglunSuccess) {
				presenter.baoBaoLeDetailComment(uid, tid);
				ByAlert.alert("回复成功");
			} else if (entity.getEventType() == TieZiPresenter.huiFuPingLunFail) {
				ByAlert.alert(entity.getData() + "回复评论失败");
			} else if (entity.getEventType() == TieZiPresenter.TieziDeleteSuccess) {
				// ByAlert.alert(entity.getData() + "qwe");
				finish();
			} else if (entity.getEventType() == TieZiPresenter.TieziDeleteFail) {
				// ByAlert.alert(entity.getData() + "");
				Intent intent = new Intent("detailfinish");
				sendBroadcast(intent);
				finish();
			} else if (entity.getEventType() == TieZiPresenter.BaoBaoLeXiangQingSuccess) {
				andHuiFuModel = (BaoBaoLePingLunAndHuiFuModel) entity.getData();
				MyAdapter adapter = new MyAdapter();
				list_wodedongtaidetail.setAdapter(adapter);
			} else if (entity.getEventType() == TieZiPresenter.PinglunSuccess) {
				ByAlert.alert("评论成功");
				presenter.baoBaoLeDetailComment(uid, tid);
			} else if (entity.getEventType() == TieZiPresenter.PingLunFail) {
				ByAlert.alert("评论失败");
			} else if (entity.getEventType() == TieZiPresenter.DeleteCommentSuccess) {
				// ByAlert.alert(entity.getData() + "");
				presenter.baoBaoLeDetailComment(uid, tid);
			} else if (entity.getEventType() == TieZiPresenter.DeleteCommentFail) {
				ByAlert.alert("删除评论失败");
			} else if (entity.getEventType() == TieZiPresenter.DeletePingLunHuiFuSuccess) {
				// ByAlert.alert(entity.getData() + "");
				presenter.baoBaoLeDetailComment(uid, tid);
			} else if (entity.getEventType() == TieZiPresenter.DeletePingLunHuiFail) {
				ByAlert.alert("删除评论的回复失败");
			} else if (entity.getEventType() == TieZiPresenter.DianzanSuccess) {
				// ByAlert.alert(entity.getData() + "");
				getYuanTie();
			} else if (entity.getEventType() == TieZiPresenter.DianzanyeFail) {
				// ByAlert.alert(entity.getData() + "");
			} else if (entity.getEventType() == TieZiPresenter.GuanzhuSuccess) {
				// ByAlert.alert(entity.getData() + "");
				getYuanTie();
			} else if (entity.getEventType() == TieZiPresenter.GuanzhuFail) {
				// ByAlert.alert(entity.getData() + "");
			}
		}
		try {
			closeProgressDialog();
		} catch (Exception e) {
			// TODO: handle exception
		}
	}

	private String uid;
	private EditText edt_reply;

	// private Button btn_reply;

	/**
	 * 弹出评论的对话框
	 * 
	 * @param parentPositon
	 *            父节点的position
	 * @param childPostion
	 *            子节点的position
	 * @return
	 */
	// protected Dialog onCreateDialog(final int parentPositon,
	// final int childPostion) {
	// final Dialog customDialog = new Dialog(WoDeDongTaiDetail2.this);
	// LayoutInflater inflater = WoDeDongTaiDetail2.this.getLayoutInflater();
	// View mView = inflater.inflate(R.layout.dialog_comment, null);
	// edt_reply = (EditText) mView.findViewById(R.id.edt_comments);
	// btn_reply = (Button) mView.findViewById(R.id.btn_send);
	//
	// customDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
	// customDialog.setContentView(mView);
	// customDialog.show();
	//
	// btn_reply.setOnClickListener(new OnClickListener() {
	//
	// @Override
	// public void onClick(View v) {
	// switch (childPostion) {
	// case ONE_COMMENT_CODE:
	// if (TextUtils.isEmpty(edt_reply.getText().toString())) {
	// Toast.makeText(WoDeDongTaiDetail2.this, "内容不能为空",
	// Toast.LENGTH_SHORT).show();
	// } else {
	// TieZiBaoHanReply.GetAList comment = new TieZiBaoHanReply.GetAList();
	// }
	// break;
	// default:
	// if (TextUtils.isEmpty(edt_reply.getText().toString())) {
	// Toast.makeText(WoDeDongTaiDetail2.this, "内容不能为空",
	// Toast.LENGTH_SHORT).show();
	// } else {
	// showProgressDialog("数据提交中，请稍后", true);
	// presenter = new TieZiPresenter(WoDeDongTaiDetail2.this);
	// if (parentPositon != -1) {
	// //
	// System.out.println("pid:"+bean.getReplyInfo().getList().get(childPostion).getPid()+"tid:"+aLists.get(childPostion).getTid()+"author_id:"+uid+"content:"+edt_reply.getText().toString()+"to_uid"+aLists.get(parentPositon).getAuthorId());
	// presenter.huiFuPingLun("4", bean.getReplyInfo()
	// .getList().get(childPostion).getPid(), bean
	// .getReplyInfo().getList().get(childPostion)
	// .getTid(), uid, edt_reply.getText()
	// .toString(), bean.getReplyInfo().getList()
	// .get(childPostion).getAuthorId());
	// // presenter.huiFuPingLun("4", "57", "109", "153",
	// // "teey", "183");
	//
	// } else {
	// presenter.pinglun(bean.getFid(), bean.getTid(),
	// bean.getauthorId(), edt_reply.getText()
	// .toString(), null, "");
	// }
	// System.out.println(">>>>>>>>>1");
	// // initCommentData();
	// customDialog.dismiss();
	// edt_reply.setText("");
	// }
	// break;
	// }
	// }
	// });
	// return customDialog;
	// }

	public class MyAdapter extends BaseAdapter {

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return andHuiFuModel.getList().size();
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return andHuiFuModel.getList().get(position);
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			ViewHolder viewHolder = null;
			if (convertView == null) {
				convertView = LayoutInflater.from(WoDeDongTaiDetail2.this)
						.inflate(R.layout.item_comment_reply_small, null);
				viewHolder = new ViewHolder();
				viewHolder.tv_comment_reply_text = (TextView) convertView
						.findViewById(R.id.tv_msg_content);
				// viewHolder.tv_comment_reply_writer = (TextView) convertView
				// .findViewById(R.id.tv_msg_title);
				// viewHolder.huifu = (TextView) convertView
				// .findViewById(R.id.huifu);
				// viewHolder.tv_comment_reply_writer2 = (TextView) convertView
				// .findViewById(R.id.tv_comment_reply_writer2);
				// viewHolder.tv_comment_reply_text2 = (TextView) convertView
				// .findViewById(R.id.tv_comment_reply_text2);
				// viewHolder.tv_comment_reply_writer2 = (TextView) convertView
				// .findViewById(R.id.tv_comment_reply_writer2);
				// viewHolder.huifupinglun = (LinearLayout) convertView
				// .findViewById(R.id.huifupinglun);
				convertView.setTag(viewHolder);
			} else {
				viewHolder = (ViewHolder) convertView.getTag();

			}
			ReplyContent reply = andHuiFuModel.getList().get(position);
			// 判断是回复楼主或者回复其他人
			// viewHolder.tv_comment_reply_writer.setText(reply.getAuthor() +
			// ":");
			// viewHolder.tv_comment_reply_text.setText(reply.getComment());
			if (!reply.getId().equals("0")) {// 回复评论
				viewHolder.tv_comment_reply_text.setText((Html
						.fromHtml("<font color=#FF6EA5>" + reply.getAuthor()
								+ "</font>" + "<font color=#8c8c8c>" + "回复"
								+ "</font>" + "<font color=#FF6EA5>"
								+ reply.getToUinfo().getNickname()
								+ "</font> ：")));
				viewHolder.tv_comment_reply_text.append(reply.getComment());
			} else {// 评论
				viewHolder.tv_comment_reply_text.setText((Html
						.fromHtml("<font color=#FF6EA5>" + reply.getAuthor()
								+ "</font>" + ":")));
				viewHolder.tv_comment_reply_text.append(reply.getComment());
			}
			// viewHolder.tv_comment_reply_text.setText(reply.getComment());
			// 判断是回复楼主或者回复其他人
			// if (reply.getComments() != null) {
			// //
			// viewHolder.tv_comment_reply_writer2.setText(Html.fromHtml(reply
			// // .getComments().get(0).getAuthor()
			// // + "<font color=\"#000000\">  回复  </font>"
			// // + reply.getAuthor() + ":"));
			// // viewHolder.tv_comment_reply_text2.setText(reply.getComments()
			// // .get(0).getComment());
			//
			// viewHolder.huifupinglun.removeAllViews();
			// for (int i = 0; i < reply.getComments().size(); i++) {
			// View view = LayoutInflater.from(WoDeDongTaiDetail2.this)
			// .inflate(R.layout.reply_view, null);
			// TextView textView1 = (TextView) view
			// .findViewById(R.id.author_one);
			// TextView textView2 = (TextView) view
			// .findViewById(R.id.author_two);
			// TextView textView3 = (TextView) view
			// .findViewById(R.id.content);
			// textView1.setText(reply.getComments().get(i).getAuthor());
			// textView2.setText(reply.getAuthor() + " :");
			// textView3.setText(reply.getComments().get(i).getComment());
			// LayoutParams params = new LayoutParams(
			// LayoutParams.WRAP_CONTENT,
			// LayoutParams.WRAP_CONTENT);
			// params.setMargins(5, 5, 5, 5);
			// viewHolder.huifupinglun.addView(view, params);
			// }
			// } else {
			// // int start = reply.getAuthor().length();
			// // String text = reply.getAuthor() + " 回复 ";
			// // SpannableStringBuilder ss = new SpannableStringBuilder(text);
			// // // 设置指定位置文字的背景颜色（将“回复”设置成灰色）
			// // ss.setSpan(
			// // new ForegroundColorSpan(Color.parseColor("#5A5A5A")),
			// // start, start + 2, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
			// // viewHolder.tv_comment_reply_writer.setText(ss);
			// }
			// 记录发表回复时，对应的position,用于确定所回复的对象，如果是楼中楼，还需记录父节点的position
			convertView.setTag(R.id.tag_second, position);
			convertView.setTag(R.id.tag_second,
					andHuiFuModel.getList().get(position).getId());
			return convertView;
		}

		class ViewHolder {
			private TextView tv_comment_reply_writer, huifu; // 评论者昵称
			private TextView tv_comment_reply_text; // 评论 内容
			private TextView tv_comment_reply_writer2; // 评论者昵称
			private TextView tv_comment_reply_text2; // 评论 内容
			private LinearLayout huifupinglun;//
		}
	}

}
